/*
 * hdu-1010 tempter of the bone
 * mike-w
 * 2012-3-25
 * ****************************************************
 */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_SIZE 10
#define Q_SIZE 100
#define cut1(x,y,d) (((abs(x-TX)+abs(y-TY))&0x1) != (d&0x1))

char f[MAX_SIZE][MAX_SIZE];
int M,N,T;
int que[Q_SIZE][2],qhead,qtail,qlen;
int tag1[MAX_SIZE][MAX_SIZE],tag2[MAX_SIZE][MAX_SIZE];
const int dd[4][2]= {1,0,-1,0,0,1,0,-1};
int SX,SY,TX,TY;

int enque(int x, int y)
{
    if(qlen==Q_SIZE)
        return -1;
    qlen++;
    que[qtail][0]=x;
    que[qtail][1]=y;
    qtail=++qtail%Q_SIZE;
    return 0;
}

int deque(int *x, int *y)
{
    if(qlen==0)
        return -1;
    qlen--;
    *x=que[qhead][0];
    *y=que[qhead][1];
    qhead=++qhead%Q_SIZE;
    return 0;
}

int BFS(void)
{
    int i,x,y,x1,y1;
    qlen=qhead=qtail=0;
    enque(SX,SY);
    tag1[SX][SY]=1;
    while(deque(&x,&y)!=-1)
    {
        for(i=0; i<4; i++)
        {
            x1=x+dd[i][0];
            y1=y+dd[i][1];
            if(x1>=0 && x1<N && y1>=0 && y1<M && !tag1[x1][y1]
                    && f[x1][y1]!='X')
            {
                enque(x1,y1);
                tag1[x1][y1]=tag1[x][y]+1;
                if(f[x1][y1]=='D')
                    return tag1[x1][y1]-1;
            }
        }
    }
    return 0;
}

int DFS(int x, int y, int d)
{
    tag2[x][y]=1;
    if(d==0)
        return f[x][y]=='D'?1:(tag2[x][y]=0);
    int i,x1,y1;
    for(i=0; i<4; i++)
    {
        x1=x+dd[i][0];
        y1=y+dd[i][1];
        if(x1>=0 && x1<N && y1>=0 && y1<M && !tag2[x1][y1]
                && f[x1][y1]!='X' && !cut1(x1,y1,d-1))
            if( DFS(x1,y1,d-1))
                return 1;
    }
    tag2[x][y]=0;
    return 0;
}

int main(void)
{
#ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
#endif
    int i,j,area;
    while(scanf("%d%d%d",&N,&M,&T)!=EOF && (M||N||T))
    {
        memset(tag1,0,sizeof(tag1));
        memset(tag2,0,sizeof(tag2));
        for(i=0; i<N; i++)
            for(scanf("%s",f[i]),j=0; j<M; j++)
                if(f[i][j]=='S')
                    SX=i,SY=j;
                else if(f[i][j]=='D')
                    TX=i,TY=j;
                else if(f[i][j]=='.')
                    area++;
        if(area+1<T || BFS()>T || cut1(SX,SY,T))
            puts("NO");
        else
            puts(DFS(SX,SY,T)?"YES":"NO");
    }
    return 0;
}